<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <div id="app">
        <button @click="obj.age++">{{obj.age}}</button>
        <button @click="changeAge">{{obj.age}}</button>
        <button @click="changeGirlAge">小红age=={{obj.girlFirend.age}}</button>
    </div>


    <script src="https://unpkg.com/vue@3/dist/vue.global.js"></script>
    <script>
        const { createApp, ref } = Vue;
        createApp({
            setup() {

                // ref 包装的对象属性值也是ref,使用时会自动解包
                const num = ref(10)

                const obj = ref({
                    name: '张三',
                    age: num,
                    gender: '男',
                    girlFirend: ref({
                        name: '小红',
                        age: 20
                    })

                })
                const changeAge = () => {
                    // obj.value.age++
                    obj.value.age++
                }
                const changeGirlAge = () => {
                    obj.value.girlFirend.age++
                }

                return {

                    obj,
                    changeAge,
                    changeGirlAge

                }

            }
        }).mount("#app")
    </script>
</body>

</html>